<template>
    <div>
      <p>用户：<input type="text" v-model="username"></p>
      <p>密码：<input type="text" v-model="password"></p>
      <p>邮箱：<input type="text" v-model="email"></p>
      <p>等级：<select v-model="grade">
          <option :value="i.id" v-for="i in list">{{i.name
            }}</option>
      </select></p>
      <p><button @click="btn">添加</button></p>
    </div>
</template>

<script>
    export default {
        name: "AddUser",
        data(){
          return{
            username:'',
            list:[],
            password:'',
            email:'',
            grade:'1'
          }
        },
        methods:{
          btn(){
            let form_data=new FormData()
            form_data.append('username',this.username)
            form_data.append('password',this.password)
            form_data.append('email',this.email)
            form_data.append('grade',this.grade)
            axios({
              url:'http://127.0.0.1:8000/app01/user/',
              method:'post',
              data:form_data
            }).then(res=>{
              console.log(res)
            })
          }
        },
        created() {
          axios({
              url:'http://127.0.0.1:8000/app01/grade/',
              method:'get',
            }).then(res=>{
              console.log(res)
            this.list=res.data
          })
        }
    }
</script>

<style scoped>

</style>